using System.Windows.Input;

namespace Silvery.GameControls
{
    public delegate void KeyHotEventHandler(HotKey hotkey);
    public class HotKey
    {
        public Key RegistKey { get; set; }
        /// <summary>
        /// 注册的组合键
        /// </summary>
        public ModifierKeys RegistModifierKeys { get; set; }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="key">注册键</param>
        /// <param name="modifierkeys">组合键，可以不写</param>
        public HotKey(Key key,ModifierKeys modifierkeys = ModifierKeys.None)
        {
            RegistKey = key;
            RegistModifierKeys = modifierkeys;
            KeyTimer = new CallTimer();
        }
        /// <summary>
        /// 构造函数，默认没有注册键和组合键
        /// </summary>
        public HotKey()
        {
            KeyTimer = new CallTimer();
            RegistKey = Key.None;
        }
        /// <summary>
        /// 一个时间记录器，可以找到创建时间
        /// 通过时间记录器可以知道最后的按键时间
        /// </summary>
        public ITimer KeyTimer { get; private set; }
        public event KeyHotEventHandler HotKeyActivated;
        public event KeyHotEventHandler HotKeyReleased;
        /// <summary>
        /// 激活事件
        /// </summary>
        public void ActivatedEvent()
        {            
            if (HotKeyActivated != null)
                HotKeyActivated(this);
            KeyTimer.Call();
        }
        public void ActivatedReleased()
        {
            if (HotKeyReleased != null)
                HotKeyReleased(this);
            KeyTimer.Call();
        }
    }
}
